import { request, USE_MOCK } from './request'

export type Order = {
  id: number
  orderNo: string
  userName: string
  phone: string
  storeName: string
  price: string
  status: string
  orderTime: string
  remark?: string
  isDelivery: boolean
  photo?: string
}

const mockOrders: Order[] = [
  {
    id: 1,
    orderNo: '202509190001',
    userName: '张三',
    phone: '13800000000',
    storeName: '海淀门店',
    price: '88.00',
    status: '已下单',
    orderTime: '2025-09-18 10:30',
    remark: '尽快送达',
    isDelivery: true
  },
  {
    id: 2,
    orderNo: '202509190002',
    userName: '李四',
    phone: '13900000000',
    storeName: '朝阳门店',
    price: '120.00',
    status: '已清洗',
    orderTime: '2025-09-18 11:00',
    remark: '',
    isDelivery: false,
    photo: 'https://via.placeholder.com/120'
  }
]

export async function getOrders(): Promise<Order[]> {
  return request({ url: '/orders', method: 'get' }, mockOrders)
}

export async function updateOrderStatus(id: number, status: string) {
  if (USE_MOCK) {
    const order = mockOrders.find(o => o.id === id)
    if (order) order.status = status
    return request({}, { code: 200, message: 'Mock 更新成功' })
  }
  return request({ url: `/orders/${id}`, method: 'put', data: { status } })
}
